package com.sbr.seb.wicket.page.administration.user;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;

import com.sbr.seb.entity.User;
import com.sbr.seb.wicket.page.administration.AdministrationBasePage;

/**
 * <p>User: Nick Heudecker</p>
 */
public class ListUsers extends AdministrationBasePage {

    public ListUsers(PageParameters params) {
        IModel<List<User>> contactsModel = new LoadableDetachableModel<List<User>>() {
			private static final long serialVersionUID = 1L;

			protected List<User> load() {
            	return null;
//                return WicketApplication.get().getContactDao().find(searchString);
            }
        };

        ListView<User> contacts = new ListView<User>("users", contactsModel) {
			private static final long serialVersionUID = 1L;

			protected void populateItem(ListItem<User> item) {
                Link<User> view = new Link<User>("view", item.getModel()) {
					private static final long serialVersionUID = 1L;

					public void onClick() {
                        User c = getModelObject();
                        setResponsePage(new ViewUser(c));
                    }
                };
                view.add(new Label("firstName", new PropertyModel<User>(item.getModel(), "firstName")));
                view.add(new Label("lastName", new PropertyModel<User>(item.getModel(), "lastName")));
                item.add(view);

//                item.add(new SmartLinkLabel("email", new PropertyModel<User>(item.getModel(), "email")));
                item.add(new Link<User>("edit", item.getModel()) {
					private static final long serialVersionUID = 1L;

					public void onClick() {
                        User user = getModelObject();
                        setResponsePage(new EditUser(user));
                    }
                });
                item.add(new Link<User>("delete", item.getModel()) {
					private static final long serialVersionUID = 1L;

					public void onClick() {
//                        User c = getModelObject();
//                        WicketApplication.get().getContactDao().delete(c.getId());
                        setResponsePage(ListUsers.class);
                    }
                });
            }
        };
        add(contacts);
    }
}
